package tech.cyhk.cloud.demo.order.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author swd
 * @date 2025/1/21
 */
@Slf4j
@Component
public class FeignRequestTokenInterceptor implements RequestInterceptor {

    @Value(value = "${spring.application.name}")
    private String applicationName;

    @Override
    public void apply(RequestTemplate template) {
        log.info("add x-token to request header");
        template.header("x-token", UUID.randomUUID().toString());
        template.header("x-application-name", applicationName);
    }
}
